/*
 * @Date: 2023-03-14 14:06:50
 * @LastEditTime: 2023-05-12 10:35:34
 * @FilePath: /wkw/src/router/importGlob.ts
 * 介绍:
 */
import { RouteRecordRaw } from "vue-router";
//@ts-ignore
import _autoImportRoutes from "~pages";

export const autoImportRoutes: RouteRecordRaw[] = _autoImportRoutes.map(
  (v: RouteRecordRaw) => {
    const meta = v.meta;
    if (typeof meta?.title !== "string") return v;
    meta.title = meta.title
      .replace(/\s*/g, "")
      .replace(/^t\('/, "")
      .replace(/'\)$/, "");
    return { ...v, meta };
  }
);

export function importRouterModules() {
  const routes: Array<RouteRecordRaw> = [];
  const modules = import.meta.glob("./module/**.ts", { eager: true });
  Object.values(modules).forEach((val: any) => {
    const module: Array<RouteRecordRaw> = val.default;
    routes.push(...module);
  });
  return routes;
}
